route.ts 1.1 KB

12345678910111213141516171819202122232425
  1. import { NextRequest, NextResponse } from 'next/server';
  2. import { ResultDto } from '@/types/response/common';
  3. import { fetchJson } from '@/lib/utils/server';
  4. export async function GET(request: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
  5. const { path } = await params;
  6. const endpoint = `/api/note/${path.join('/')}`;
  7. const url = new URL(request.url);
  8. const res: ResultDto = await fetchJson(`${endpoint}${url.search}`, { method: 'GET' });
  9. return NextResponse.json(res);
  10. }
  11. export async function POST(request: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
  12. const { path } = await params;
  13. const endpoint = `/api/note/${path.join('/')}`;
  14. const res: ResultDto = await fetchJson(endpoint, { method: 'POST', body: (await request.text()) || '{}' });
  15. return NextResponse.json(res);
  16. }
  17. export async function DELETE(_: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
  18. const { path } = await params;
  19. const endpoint = `/api/note/${path.join('/')}`;
  20. const res: ResultDto = await fetchJson(endpoint, { method: 'DELETE' });
  21. return NextResponse.json(res);
  22. }